﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.Entity;
using System.Data.EntityModel;
using MINERP.DAL;
using MINERP.DAL.ShowDataControl;

namespace MINERP.BLL.ShowDataControlBLL
{
    public class DataControlBLL
    {
        private DAL.ShowDataControl.DataControlDAL DSD = new MINERP.DAL.ShowDataControl.DataControlDAL();
        #region 删除指定的订单集合
        /// <summary>
        /// 删除指定的订单集合
        /// </summary>
        /// <param name="orderIds"></param>
        public void DelOrderBags(string orderIds)
        {
            try
            {
                string[] ids = orderIds.Split(',');
                List<int> orderIdss = new List<int>();
                foreach (string id in ids)
                {
                    int id2 = Convert.ToInt32(id);
                    orderIdss.Add(id2);
                }
                DSD.DelOrderBags(orderIdss);
            }
            catch
            {
                return;
            }
        }
        #endregion

        /// <summary>
        /// 改变订单集合的状态到等待分配打印机
        /// </summary>
        /// <param name="ids"></param>
        public void ChangeStatuToDistributePrinter(string orderIds)
        { 
            //修改订单下所有产品的状态到等待分配打印机
            //所有照片的状态改为未分配打印机
            try
            {
                List<int> orderIdss=new List<int>();
                string[] ids=orderIds.Split(',');
                foreach(string id in ids)
                {
                    int id2=Convert.ToInt32(id);
                    orderIdss.Add(id2);
                }

                //修改产品的流程状态
                List<orderInfo> products = DSD.GetOrderInfoInOrderIds(orderIdss);
                List<WorkOrderFlowList> flows = DSD.GetFlows(products, 4);          //获取指定产品下所有的"调色"节点
                foreach (WorkOrderFlowList w in flows)
                {       
                    w.Status = 4;
                }
                List<WorkOrderFlowList> flows2 = DSD.GetFlows(products, 5);         //获取指定产品下所有的"打印管理"节点
                foreach (WorkOrderFlowList w in flows2)
                {
                    w.Status = 1;
                }
                List<WorkOrderFlowList> flows3 = DSD.GetFlows(products, 6);         //获取指定产品下所有的"拼版"节点
                foreach (WorkOrderFlowList w in flows3)
                {
                    w.Status = 0;
                }

                //修改照片状态
                List<photoInfo> photos = DSD.GetPhotoInProducts(products);
                foreach (photoInfo p in photos)
                {
                    p.status = 0;
                }
                DSD.SaveDataChanges();
            }
            catch
            {
                return;
            }
        }
    }
}
